const Handlebars = require('handlebars')

const temp = {
  csharp: `
  {{#each tabledata}}
  /// <summary>
  /// {{this.name}}
  /// </summary>
  public string {{this.code}} { get; set; }
  
  
  {{/each}}

`,
  jsapi: `
import request from '@/utils/request'
 
const apiPrefix = process.env.VUE_APP_BASE_API

 
export const list = (params, config = {}) => {
  return request.post(apiPrefix + '{{form.listapi}}', params, config)
}
export const del = (params, config = {}) => {
  return request.delete(apiPrefix + '{{form.delapi}}', { params: params, ...config })
}
export const update = (params, config = {}) => {
  return request.put(apiPrefix + '{{form.updateapi}}', params, config)
}
 
export const add = (params, config = {}) => {
  return request.post(apiPrefix + '{{form.addapi}}', params, config)
}
 



`,
  jsoption: `
  export default safe => {
    console.log(safe) // vue的this对象
    return {
      index: true,
      selection: true,
      align: 'center',
      headerAlign: 'center',
      border: true,
      stripe: true,
      searchMenuSpan: 8,
      column: [
{{#each tabledata}}
{
  label: '{{this.name}}',
  prop: '{{this.code}}',  
  addDetail:{{this.addDetail}},
addDisabled:{{this.addDisabled}},
addDisplay:{{this.addDisplay}}, 
editDetail:{{this.editDetail}},
editDisabled:{{this.editDisabled}},
editDisplay:{{this.editDisplay}}, 
required:{{this.required}},
search:{{this.search}},
showColumn:{{this.showColumn}},
type:"{{this.type}}",
  rules: [
    {{#if this.required}}
    {
      required: true,
      message: '请输入{{this.name}}',
      trigger: 'blur'
    }
    {{/if}}
  ]
},
{{/each}} 
      ]
    }
  }
  
  
  `,
  jsvue: `
  <template>
  <basic-container>
    <avue-crud
      v-model="form"
      v-bind="bindVal"
      :page.sync="page"
      v-on="onEvent"
    >
      
    </avue-crud>
  </basic-container>
</template>

<script>
 
export default window.$crudCommon({
  data() {
    return {
      roledic: []
    }
  },
  mounted() {
    
  },
  methods: {
    // 列表前操作方法
    listBefore() {},

    // 列表后操作方法
    listAfter() {},

    // 新增前操作方法
    addBefore() {
      //this.form
    },
    // 新增后操作方法
    addAfter() {},

    // 修改前操作方法
    updateBefore() {
      this.form.updateUser = 'small'
    },

    // 修改后操作方法
    updateAfter() {},

    // 删除后操作方法
    delAfter() {}
  }
}, {
  name: '{{form.viewcode1}}', // 模块名字
  list: 'list', // 列表接口名字
  update: 'update', // 更新接口名字
  add: 'add', // 新增接口名字
  del: 'del', // 删除接口名字
  rowKey: 'id', // 主键
  pageNumber: 'pageNumber', // 页码
  pageSize: 'pageSize', // 页数
  res: (data) => {
    return {
      total: 0,
      list: []
    }
  }, // 列表的结构
  total: 'total', // 总页数
  data: 'list'// 列表属性
})
</script>
<style lang="scss" scoped>
</style>

  
  
  `
}

export function getresult(tempname, data) {
  const template = Handlebars.compile(temp[tempname])
  return template(data)
}
